package com.foreknow.service.impl;

import com.foreknow.dao.AdminDao;
import com.foreknow.dao.impl.AdminDaoImpl;
import com.foreknow.db.DBManager;
import com.foreknow.db.JdbcTemplate;
import com.foreknow.model.Admin;
import com.foreknow.service.AdminService;

import java.sql.Connection;
import java.sql.SQLException;

public class AdminServiceImpl implements AdminService {


    @Override
    public Admin login(Admin admin) throws SQLException {
        Admin admin1=null;
        //链接数据库
        AdminDao adminDao=new AdminDaoImpl();
        DBManager instance1 = DBManager.getInstance();
        Connection connection = instance1.getConnection();
        JdbcTemplate instance = JdbcTemplate.getInstance();
        instance.setConnection(connection);

        try {
            admin1 = adminDao.login(admin);
        } catch (SQLException e) {
            e.printStackTrace();
        }

        return admin1;
    }

    @Override
    public boolean register(Admin admin) {
        boolean isregister=false;

        //链接数据库
        AdminDaoImpl adminDao=new AdminDaoImpl();
        DBManager instance1 = DBManager.getInstance();
        Connection connection = instance1.getConnection();
        JdbcTemplate instance = JdbcTemplate.getInstance();
        instance.setConnection(connection);

        try {
            isregister= adminDao.register(admin);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return isregister;
    }
}
